#ifndef UIMANAGER_H
#define UIMANAGER_H
#include "Enums.h"
#include "controller.h"
#include "mainwindow.h"
#include "defaultpage.h"
#include "emailverify.h"
#include "frm_login.h"
#include "frm_querypage.h"
#include "user.h"
#include "frm_userpage.h"
#include "frm_register.h"
#include <QDateEdit>
#include <QLineEdit>
#include <QCalendarWidget>
#include <QEvent>
class UIManager:QObject
{
    Q_OBJECT
private:
    MainWindow* mainw;
    DefaultPage* df;
    EmailVerify* em;
    Frm_Login* lg;
    Frm_Register* rg;
    Controller* controller;
    frm_QueryPage* qp;
    frm_UserPage* up;
public:
    //bool eventFilter(QObject* watched, QEvent* event) override;
    UIManager(Controller* control):controller(control){
        mainw = new MainWindow();
        lg = new Frm_Login();
        rg = new Frm_Register();
        em = new EmailVerify();
        df = new DefaultPage();
        qp = new frm_QueryPage();
        up = new frm_UserPage();
        //floaty = new FloatWidget();
        connect(this->em,&EmailVerify::request_verify_code,this->controller,&Controller::RequestForVerify);
        connect(this->rg,&Frm_Register::RequestForVerify,this->controller,&Controller::RequestForVerify);
        connect(this->lg,&Frm_Login::RequestForEmailVerifier,this->controller,&Controller::EmailVerifierRequested);
        connect(this->lg,&Frm_Login::RequestForRegister,this->controller,&Controller::RegisterRequested);
        connect(df,&DefaultPage::RequestForQuery,this->controller,&Controller::RequestForQueryModel);
        connect(mainw,&MainWindow::destroyed,this->controller,&Controller::exitApp);
        connect(rg,&Frm_Register::RequestForNewUser,this->controller,&Controller::RequestNewUser);
        //QDateEdit* dt = df->findChild<QDateEdit*>("dt_onw_time");
        //dt->installEventFilter(this);
        //connect(floaty,&FloatWidget::SelectedDateChanged,this,&UIManager::ChangedDateEdit);
        connect(lg,&Frm_Login::RequestForLogin,controller,&Controller::RequestForLogin);
        connect(em,&EmailVerify::RequestForLogin,controller,&Controller::RequestForLogin);
        connect(qp,&frm_QueryPage::PageChanged,controller,&Controller::QueryModelPageSet);
        connect(qp,&frm_QueryPage::returnToMain,controller,&Controller::SetDefault);
        connect(qp,&frm_QueryPage::RequestForOrder,controller,&Controller::OrderPageRequested,Qt::QueuedConnection);
        connect(up,&frm_UserPage::changeUserData,controller,&Controller::changeUserData);
        connect(up,&frm_UserPage::RequestQueryModel,controller,&Controller::OrderModelRequest);
        connect(mainw,&MainWindow::OnUserPage,controller,&Controller::RequestForUserPage);
        connect(mainw,&MainWindow::OnDefaultPage,controller,&Controller::SetDefault);
        connect(up,&frm_UserPage::RequestUserModel,controller,&Controller::RequestForUserModel);
        mainw->InitStackedWidget({df,qp,up});
    }
    MainWindow* getMainWindow(){return mainw;}
    DefaultPage* getDefaultPage(){return df;}
    EmailVerify* getEmailVerifier(){return em;}
    Frm_Login* getFrmLogin(){return lg;}
    Frm_Register* getFrmRegister(){return rg;}
    frm_QueryPage* getQueryPage(){return qp;}
    void LoginDone(){
        lg->accept();
        mainw->show();
    }
    frm_UserPage* getUserPage(){return up;}
    //void OnQueryDone(QJsonObject)
public slots:
    //void ChangedDateEdit(QDate d,QDateEdit* target);
};

#endif // UIMANAGER_H
